using System;
namespace APP.HELPER.Utils.BarcodeLib
{
	internal class Code11 : BarcodeCommon, IBarcode
	{
		private string[] C11_Code = new string[]
		{
			"101011",
			"1101011",
			"1001011",
			"1100101",
			"1011011",
			"1101101",
			"1001101",
			"1010011",
			"1101001",
			"110101",
			"101101",
			"1011001"
		};
		public string Encoded_Value
		{
			get
			{
				return this.Encode_Code11();
			}
		}
		public Code11(string input)
		{
			this.Raw_Data = input;
		}
		private string Encode_Code11()
		{
			if (!BarcodeEdit.CheckNumericOnly(this.Raw_Data.Replace("-", "")))
			{
				throw new Exception("EC11-1: Numeric data and '-' Only");
			}
			int num = 1;
			int num2 = 0;
			string text = this.Raw_Data;
			for (int i = this.Raw_Data.Length - 1; i >= 0; i--)
			{
				if (num == 10)
				{
					num = 1;
				}
				if (this.Raw_Data[i] != '-')
				{
					num2 += int.Parse(this.Raw_Data[i].ToString()) * num++;
				}
				else
				{
					num2 += 10 * num++;
				}
			}
			text += (num2 % 11).ToString();
			if (this.Raw_Data.Length >= 1)
			{
				num = 1;
				int num3 = 0;
				for (int i = text.Length - 1; i >= 0; i--)
				{
					if (num == 9)
					{
						num = 1;
					}
					if (text[i] != '-')
					{
						num3 += int.Parse(text[i].ToString()) * num++;
					}
					else
					{
						num3 += 10 * num++;
					}
				}
				text += (num3 % 11).ToString();
			}
			string str = "0";
			string str2 = this.C11_Code[11] + str;
			string text2 = text;
			for (int j = 0; j < text2.Length; j++)
			{
				char c = text2[j];
				int num4 = (c == '-') ? 10 : int.Parse(c.ToString());
				str2 += this.C11_Code[num4];
				str2 += str;
			}
			return str2 + this.C11_Code[11];
		}
	}
}
